package com.codedef.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.codedef.entity.JwtParam;
import com.codedef.entity.User;
import com.codedef.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author 孙宏宇
 * @date 2021/2/22 09:56
 */
@Service
public class UserService {

    @Autowired
    UserMapper userMapper;

    @Autowired
    JwtParam jwtParam;

    /**
     * 增加一次用户的预约次数
     */
    public void increaseReservationNumber(Integer userId) {
        userMapper.increaseReservationNumber(userId);
    }

    /**
     * 通过Id获得用户信息
     * @return 用户实体类
     */
    public User getCurrentUserInfo(Integer userId) {
        // 从Jwt获取载荷
        User user = userMapper.selectOne(new QueryWrapper<User>().eq("id", userId));
        user.setPassword(null);
        user.setSalt(null);

        return user;
    }

    /**
     * 将用户的违约次数+1
     * @param userId 用户的id
     */
    public void increaseDefaultNumber(Integer userId) {
        userMapper.increaseDefaultNumber(userId);
    }

}
